package com.fjp.heartguard.app.weight

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.CompoundButton
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import com.fjp.heartguard.R

/**
 *Author:Mr'x
 *Time:2024/11/1
 *Description:
 */
class MineItemLayout(context: Context, attrs: AttributeSet) : LinearLayoutCompat(context, attrs) {
    lateinit var titleTv: TextView
    lateinit var valueTv: TextView
    lateinit var iconIv: ImageView
    lateinit var listener: CompoundButton.OnCheckedChangeListener

    init {
        LayoutInflater.from(context).inflate(R.layout.layout_item_mine, this);
        val typeAttay = context.obtainStyledAttributes(attrs, R.styleable.MineItemLayout)
        val title = typeAttay.getString(R.styleable.MineItemLayout_title)
        val value = typeAttay.getString(R.styleable.MineItemLayout_value)
        val icon = typeAttay.getResourceId(R.styleable.MineItemLayout_icon, 0)
        typeAttay.recycle()
        iconIv = findViewById(R.id.iconIv)
        titleTv = findViewById(R.id.titleTv)
        valueTv = findViewById(R.id.valueTv)
        titleTv.text = title
        valueTv.text = value
        iconIv.setImageResource(icon)


    }

    fun setValue(value: String, startDrawalbeID: Int = 0) {
//        if (startDrawalbeID != 0) {
//            valueTv.setCompoundDrawablesRelativeWithIntrinsicBounds(ContextCompat.getDrawable(context, startDrawalbeID), null, ContextCompat.getDrawable(context, R.drawable.setting_arrow), null)
//        }
        valueTv.text = value
    }

    fun setTitle(title: String) {
        titleTv.text = title
    }

}